/*
 * v1.1 by tonydon site:txdnet.cn
 * netbeansIDE 7.1
 */
package cn.txdnet.txcms.service;

import cn.txdnet.txcms.dao.LinksDAO;
import cn.txdnet.txcms.domain.Links;
import cn.txdnet.txcms.dto.PageDTO;
import cn.txdnet.txcms.query.LinksQuery;
import cn.txdnet.txweb.basedao.FacadeProxy;
import cn.txdnet.txweb.utils.StringUtil;
import java.util.HashMap;
import java.util.Map;
import txdnet.util.StaticMark;

/**
 *
 * @author txdnet
 */
public class LinksService {

    /*
     * 建立新链接
     */
    public static boolean make(Links lk) {
        LinksDAO dao = FacadeProxy.getManualCommitProxy(LinksDAO.class);
        return (dao.insertLink(lk) > 0 ? true : false);
    }

//     删除链接
    public static int deleteBatch(String ids) {
        LinksDAO dao = FacadeProxy.getManualCommitProxy(LinksDAO.class);
        return dao.deleteLink(StringUtil.parseStrToIntArray(ids, StaticMark.STR_LINE));
    }

    public static boolean update(Links lk) {
        LinksDAO dao = FacadeProxy.getManualCommitProxy(LinksDAO.class);
        return (dao.updateLink(lk) > 0 ? true : false);
    }

    /**
     * 批量更新发布状态
     * @param ids
     * @param pubstate
     * @return 
     */
    public static int updatePubstateBatch(String ids, byte pubstate) {
        Map<String, Object> m = new HashMap<String, Object>(2);
        m.put("ida", StringUtil.parseStrToIntArray(ids, StaticMark.STR_LINE));
        m.put("pubstate", pubstate);
        LinksDAO dao = FacadeProxy.getManualCommitProxy(LinksDAO.class);
        return dao.updatePubstate(m);
    }

    /**
     * 更新权重
     *
     * @param lkid
     * @param weight
     * @return
     */
    public static int updateWeight(int lkid, int weight) {
        Map<String, Object> m = new HashMap<String, Object>(2);
        m.put("lkid", lkid);
        m.put("weight", weight);
        LinksDAO dao = FacadeProxy.getManualCommitProxy(LinksDAO.class);
        return dao.updateWeight(m);
    }
    
        /**
     * 批量更新类目
     *
     * @param ids
     * @param cid
     * @param ctp
     * @return
     */
    public static int updateCatalogBatch(String ids, int cid, String ctp) {
        Map<String, Object> m = new HashMap<String, Object>(3);
        m.put("ida", StringUtil.parseStrToIntArray(ids, StaticMark.STR_LINE));
        m.put("cid", cid);
        m.put("ctp", ctp);
        LinksDAO dao = FacadeProxy.getManualCommitProxy(LinksDAO.class);
        return dao.updateCatalog(m);
    }

    /**
     * 查询最大权重值
     *
     * @return
     */
    public static int queryMaxWeight() {
        LinksDAO dao = FacadeProxy.getAutoCommitProxy(LinksDAO.class);
        return dao.queryMaxWeight();
    }

//    查询链接列表
    public static PageDTO listByFactor(LinksQuery query) {
        LinksDAO dao = FacadeProxy.getAutoCommitProxy(LinksDAO.class);
        return dao.queryByFactor(query);
    }

//     查询链接详情
    public static Links query(int lkid) {
        LinksDAO dao = FacadeProxy.getAutoCommitProxy(LinksDAO.class);
        return dao.queryLink(lkid);
    }
}
